package castle.defense.project;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.WindowManager;

/**
 * The activity that is first called when the game is opened. Linked to the menu, essentially a wrapper class.
 * @author Daniel Wasserman
 *
 */
public class CastleDefenseActivity extends Activity implements OnFocusChangeListener {
	
	public static boolean internal = false;
	private MenuView mv;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		Options.initialize(this);
		SoundManager.initializeSoundManager(this);
		GraphicsEngine.addImage(SoftButton.buttonBackground, this.getResources().getDrawable(R.drawable.stonewallbutton));
		GraphicsEngine.setBackground(this.getResources(), R.drawable.grass);
	}

	@Override
	public void onResume() {
		SoundManager.setBackground(R.raw.medieval_menu);
		mv = new MenuView(this);
		this.setContentView(mv);
		super.onResume();
	}
	
	@Override
	public void onPause() {
		if(!internal) {
			SoundManager.pauseBackground();
		} else {
			internal = false;
		}
		super.onPause();
	}
	
	@Override
	public void onStop()
	{
		mv.stop();
		super.onStop();
	}
	
	@Override
	public void onDestroy() {
		SoundManager.stopBackground();
		super.onDestroy();
	}
	
	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		if(hasFocus) {
			SoundManager.resumeBackground();
		} else {
			SoundManager.pauseBackground();
		}
	}
}